$(function () {
    $('button').click(function () {
        var tel = $('input[name=tel]');
        var password = $('input[name=password]');
        var code = $('input[name=code]');
        if (tel.val() == null || tel.val() == undefined || tel.val() == '') {
            layer.msg('登录手机号不能为空');
            tel.focus();
            return false;
        }
        if (!(/^((\d{3}-\d{8}|\d{4}-\d{7,8})|(1[3|5|7|8][0-9]{9}))$/.test(tel.val()))) {
            layer.msg('手机号格式错误');
            tel.focus();
            return false;
        }
        if (password.val() == null || password.val() == undefined || password.val() == '') {
            layer.msg('登录密码不能为空');
            password.focus();
            return false;
        }
        if (code.val() == null || code.val() == undefined || code.val() == '') {
            layer.msg('验证码不能为空');
            code.focus();
            return false;
        }
        $.post("/member/login",
            {
                tel: tel.val(),
                password: password.val(),
                code: code.val(),
                _token: $('input[name=_token]').val()
            },
            function (data) {
                if (data.status == 200) {
                    layer.msg(data.msg);
                    setTimeout(function () {
                        window.location.href = data.data;
                    }, 500);
                } else if (data.status == 4000) {
                    $('#code').attr('src', "/code?" + Math.random());
                    layer.msg(data.msg);
                } else {
                    layer.msg(data.msg);
                }
            });
    })
});